package routes

import (
	"net/http"

	"codeberg.org/vnpower/pixivfe/v2/audit"
	"codeberg.org/vnpower/pixivfe/v2/core"
)

func NewestPage(auditor *audit.Auditor, w http.ResponseWriter, r *http.Request) error {
	worktype := GetQueryParam(r, "type", "illust")

	r18 := GetQueryParam(r, "r18", "false")

	works, err := core.GetNewestArtworks(auditor, r, worktype, r18)
	if err != nil {
		return err
	}

	return RenderHTML(w, r, Data_newest{
		Items: works,
		Title: "Newest works",
	})
}
